<?php
namespace api\modules\mp;

use yii;

/**
 * @author qingyu8@staff.weibo.com
 * @date 2018/02/01
 */
class Module extends yii\base\Module {
    public function init() {
        parent::init();
        //小程序登录态
        //var_dump(\Yii::$app->user->getIdentity()->getId());exit;
        Yii::$app->user->enableSession = false;
        Yii::$app->user->identityClass = Yii::createObject(['class' => 'api\modules\mp\models\User']);

        Yii::$app->response->on(yii\web\Response::EVENT_BEFORE_SEND, function($event) {
            $response = $event->sender;
            if (isset($response->data['type']) && strpos($response->data['type'], 'Exception') !== false) {
                $response->data = [
                    'code' => $response->data['status'],
                    'msg' => $response->data['name'],
                ];
            }
        });

    }
}
